package com.example.shop.sys.web;

import com.example.shop.base.BaseController;
import com.example.shop.common.configs.SystemConfig;
import com.example.shop.common.utils.Constants;
import com.example.shop.common.utils.LocalFileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * 文件上传下载方法
 *
 * @author haocj
 */
@Controller
public class FileController extends BaseController {

    @Value("${system.profile.path}")
    private String profile;

    @Value("${system.profile.real_path}")
    private String realProfile;

    @RequestMapping("/profile/{id}/{date}/{fileName:.+}")
    @ResponseBody
    public String loadImg(@PathVariable String id, @PathVariable String date, @PathVariable String fileName,
                          HttpServletRequest request, HttpServletResponse response) throws IOException {
        String path = realProfile + "/" + id + "/" + date + "/" + fileName;
        LocalFileUtils.outWriterFile(fileName, path, request, response);

        return null;
    }

}
